package cn.edu.njust.alg.leetcode;

import java.util.ArrayList;
import java.util.List;

import cn.edu.njust.alg.ArrayUtils;
import cn.edu.njust.alg.ListUtils;

/**
 * 创建时间：2015年6月15日 上午11:47:37 项目名称：AlgorithmExercise
 * 
 * @author Zhou Xiumin
 * @version 1.0
 * @since JDK 1.7.0_21 文件名称：Leetcode_0_t.java 类说明：
 */
public class Leetcode_199_Binary_Tree_Right_Side_View {

	public static void travel(TreeNode node, int level, List<Integer> list) {
		if (node == null) {
			return;
		}
		if (level > list.size()) {
			list.add(node.val);
		}
		travel(node.right, level + 1, list);
		travel(node.left, level + 1, list);
	}

	public static List<Integer> rightSideView(TreeNode root) {
		List<Integer> list = new ArrayList<Integer>();
		if (root == null) {
			return list;
		}
		int level = 1;
		list.add(root.val);
		travel(root.right, level + 1, list);
		travel(root.left, level + 1, list);
		return list;
	}

	public static void main(String[] args) {
		TreeNode node1 = new TreeNode(1);
		TreeNode node2 = new TreeNode(2);
		TreeNode node3 = new TreeNode(3);
		TreeNode node4 = new TreeNode(4);
		TreeNode node5 = new TreeNode(5);
		node1.left = node2;
		node2.right = node5;
		node1.right = node3;
		node3.right = node4;
		ListUtils.printList(rightSideView(node1));

	}

}
